<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getContextPath();
    String path = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+basePath+"/";
    request.setAttribute("path",path);
    
    String unionid = (String)request.getSession().getAttribute("unionid");
%>
<html>
<head>
    <title>微信支付结果</title>
  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />

</head>
<script type="text/javascript" src="http://www.kaaction.com/show/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="http://www.kaaction.com/show/jquery/jquery.js"></script>
<script>

var openid="<%=session.getAttribute("openid")%>";   
var customerid="<%=session.getAttribute("customerid")%>";   

function onBridgeReady(){
	   WeixinJSBridge.invoke(
	       'getBrandWCPayRequest', {
	           "appId":"wx079bba8222507669",     //公众号名称，由商户传入     
	           "timeStamp":"${timeStamp}",         //时间戳，自1970年以来的秒数     
	           "nonceStr":"${nonce_str}", //随机串     
	           "package":"prepay_id=${prepay_id}",     
	           "signType":"MD5",         //微信签名方式：     
	           "paySign":"${sign}" //微信签名 
	       },
	       function(res){   
	           if(res.err_msg == "get_brand_wcpay_request:ok" ) {
	        	   location.href="http://www.kaaction.com/show/index.html?openid="+openid+"&customerid="+customerid;
	           } else if(res.err_msg == "get_brand_wcpay_request:cancel"){
	        	   alert("您取消了支付...");
	        	   //history.go(-1);
	        	   location.href="http://www.kaaction.com/show/index.html?openid="+openid+"&customerid="+customerid;
	           } else if(res.err_msg == "get_brand_wcpay_request:fail"){
	        	   alert("支付失败了...");
	           }  
	          
	       }
	   ); 
	}
	if (typeof WeixinJSBridge == "undefined"){
	   if( document.addEventListener ){
	       document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	   }else if (document.attachEvent){
	       document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	       document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	   }
	}else{
	   onBridgeReady();
	}
</script>
<body>
<form id="form1" name="form1" method="post" action="http://www.kaaction.com/show/index.html">
    <input type="hidden" id="unionid" name="unionid" value="${unionid}" />
</form>

</body>
</html>
